package game;

import util.SuperArray;

import javax.swing.*;

/**
 * 玩家类
 */
public class Player {
    /**
     * 用户输入的四位不重复的数字
     * @return
     */
    public SuperArray inputNumber(){
        SuperArray ary = null;
        while(true){
            ary = new SuperArray();
            String input = JOptionPane.showInputDialog(null,"请输入不重复的四位数");
            if(input.length() != 4){
                JOptionPane.showMessageDialog(null,"必须输入四位数字");
                continue;
            }
            char [] cs = input.toCharArray();
            boolean flag = true;
            for(int i = 0;i < cs.length;i++){
                if(cs[i] < '0' || cs[i] > '9'){
                    flag = false;
                    JOptionPane.showMessageDialog(null,"输入的必须为0-9之间的数字");
                    break;
                }
                for(int j = i + 1;j < cs.length;j++){
                    if(cs[i] == cs[j]){
                        flag = false;
                        JOptionPane.showMessageDialog(null,"不能输入重复的数字");
                        break;
                    }
                }
                if(!flag){
                    break;
                }
                ary.add(cs[i]);
            }
            if(flag){
                break;
            }
        }
        return ary;

    }
}
